#define _CRT_SECURE_NO_WARNINGS 1
int Sizetree(struct TreeNode* root)
{
    if (root == NULL)
    {
        return 0;
    }
    return Sizetree(root->left) + Sizetree(root->right) + 1;
}

void Backorder(int* a, struct TreeNode* root, int* pi)
{
    if (root == NULL)
    {
        return;
    }
    Backorder(a, root->left, pi);
    Backorder(a, root->right, pi);
    a[(*pi)++] = root->val;
}

int* postorderTraversal(struct TreeNode* root, int* returnSize) {
    int n = Sizetree(root);
    *returnSize = n;
    int* a = NULL;
    int* tmp = (int*)malloc(sizeof(int) * n);
    if (tmp == NULL)
    {
        perror("malloc fail");
        return 0;
    }
    a = tmp;
    int i = 0;
    int* pi = &i;
    Backorder(a, root, pi);
    return a;
}